﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StreetSmartAdmin
{
    public partial class CMS : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedValue == "AccountStatus")
            {
                MultiView1.ActiveViewIndex = 1;
            }
            else if (DropDownList1.SelectedValue == "PromotionCode")
            {
                MultiView1.ActiveViewIndex = 2;
            }
            else if (DropDownList1.SelectedValue == "SourceCodeRESI")
            {
                MultiView1.ActiveViewIndex = 3;
            }
            else if (DropDownList1.SelectedValue == "SourceCodeSME")
            {
                MultiView1.ActiveViewIndex = 4;
            }
            else if (DropDownList1.SelectedValue == "ProductTypeRESI")
            {
                MultiView1.ActiveViewIndex = 5;
            }
            else if (DropDownList1.SelectedValue == "ProductTypeSME")
            {
                MultiView1.ActiveViewIndex = 6;
            }
            else if (DropDownList1.SelectedValue == "Operator")
            {
                MultiView1.ActiveViewIndex = 7;
            }
            else
            {
                MultiView1.ActiveViewIndex = 0;
            }
        }

        protected void insertRecord(string table, string field, string value)
        {
            string insertcommand = "insert into " + table + " (" + field + ") values('" + value + "');";
            string connectionString = null;
            System.Configuration.ConnectionStringSettings connString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLServer2005DBConnectionString"];
            if (null != connString)
                connectionString = connString.ConnectionString;
            System.Data.SqlClient.SqlConnection connection = null;
            connection = new System.Data.SqlClient.SqlConnection(connectionString);
            connection.Open();
            System.Data.SqlClient.SqlCommand command;
            command = connection.CreateCommand();
            command.CommandText = insertcommand;
            command.ExecuteNonQuery();
            connection.Close();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!(TextBox1.Text == ""))
            {
                insertRecord("tblAccountStatus", "AccountStatusName", TextBox1.Text);
                GridView1.DataBind();
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (!(TextBox2.Text == ""))
            {
                insertRecord("tblPromotionCode", "PromotionCodeName", TextBox2.Text);
                GridView2.DataBind();
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            if (!(TextBox3.Text == ""))
            {
                insertRecord("SourceCodeRESI", "SourceCodeRESI_Name", TextBox3.Text);
                GridView3.DataBind();
            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            if (!(TextBox4.Text == ""))
            {
                insertRecord("SourceCodeSME", "SourceCodeSME_Name", TextBox4.Text);
                GridView4.DataBind();
            }
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            if (!(TextBox5.Text == ""))
            {
                insertRecord("ProductTypeRESI", "ProductTypeRESI_Name", TextBox5.Text);
                GridView5.DataBind();
            }
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            if (!(TextBox6.Text == ""))
            {
                insertRecord("ProductTypeSME", "ProductTypeSME_Name", TextBox6.Text);
                GridView6.DataBind();
            }
        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            if (!(TextBox7.Text == ""))
            {
                insertRecord("tblOperator", "OperatorName", TextBox7.Text);
                GridView7.DataBind();
            }
        }
    }
}